package com.group.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.group.pojo.TbAttrName;
import com.group.service.AttrNameService;
import com.group.util.CommonUtil;

@Controller
@RequestMapping("/attrName")
public class AttrNameController {
	@Autowired
	private AttrNameService attrNameService;

	// 跳转属性视图
	@RequestMapping("/page.action")
	public String attrPage() {
		return "info/device/attr-name";
	}

	// 查询所有的属性
	@RequestMapping("/query.action")
	@ResponseBody
	public List<TbAttrName> query(TbAttrName attrName) {
		return attrNameService.query(attrName);
	}
	
	// 添加属性名
	@RequestMapping("save.action")
	@ResponseBody
	public Map<String, String> save(HttpServletRequest request, TbAttrName attrName) {
		Map<String, String> map = attrNameService.save(request, attrName);
		return map;
	}

	// 根据属性id查询属性信息
	@RequestMapping("getAttrById.action")
	@ResponseBody
	public List<TbAttrName> getAttrById(String id) {
		return attrNameService.getAttrById(id);
	}

	// 修改属性
	@RequestMapping("/update.action")
	@ResponseBody
	public Map<String, String> update(TbAttrName attrName) {
		return attrNameService.update(attrName);
	}

	// 删除属性
	@RequestMapping("/batchDelete.action")
	@ResponseBody
	public Map<String, String> batchDelete(@RequestParam(value = "attrIds[]") String[] attrIds) {
		Map<String, String> map = attrNameService.batchDelete(attrIds);
		return map;
	}

	// 更具属性id获得属性名称
	@RequestMapping("/getAttrNameById.action")
	@ResponseBody
	public String getAttrNameById(String attrNameId) {
		String attrName = attrNameService.getAttrNameById(attrNameId);
		return attrName;
	}

	// 检查属性名称
	@RequestMapping("/CheckattrName.action")
	@ResponseBody
	public String CheckattrName(String attrName) {
		String success = attrNameService.CheckattrName(attrName);
		return success;
	}

	// 修改时检查属性名称
	@RequestMapping("/updateCheckattrName.action")
	@ResponseBody
	public String updateCheckattrName(String attrName,String id) {
		String success = attrNameService.updateCheckattrName(attrName,id);
		return success;
	}
	
}
